﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineTestBLL;

namespace OnlineTestUI.BackManager
{
    public partial class studentlist : System.Web.UI.Page
    {
        private StudentsBLL sb = new StudentsBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }

        }
        #region BindGrid
        private void BindGrid()
        {
            // 1.设置总项数（特别注意：数据库分页一定要设置总记录数RecordCount）
            GridStudent.RecordCount = sb.GetRecordCount("");

            // 2.获取当前分页数据
            DataTable table = GetPagedDataTable();

            GridStudent.DataSource = table;

            GridStudent.DataBind();
        }


        /// <summary>
        /// 数据库分页
        /// </summary>
        /// <returns></returns>
        private DataTable GetPagedDataTable()
        {
            int pageIndex = GridStudent.PageIndex;
            int pageSize = GridStudent.PageSize;

            string sortField = GridStudent.SortField;
            string sortDirection = GridStudent.SortDirection;

            int rowbegin = pageIndex * pageSize+1;
            int rowend = (pageIndex + 1) * pageSize;
            string orderby = String.Format("{0} {1}", sortField, sortDirection);
            DataTable paperList = sb.GetListByPage("", @orderby, rowbegin, rowend).Tables[0];

            return paperList;
        }

        #endregion

        #region Events




        protected void GridStudent_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
        {
            GridStudent.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        protected void GridStudent_Sort(object sender, FineUI.GridSortEventArgs e)
        {
            GridStudent.SortDirection = e.SortDirection;
            GridStudent.SortField = e.SortField;
            BindGrid();
        }

        #endregion


    }
}